Page({
  data: {
    List: [],
    loading: false
  },
  
  onLoad() {
    this.GetList();
  },
  
  GetList() {
    const that = this; // 保存this引用
    that.setData({ loading: true });
    
    wx.request({
      url: 'https://live-api.itheima.net/announcement',
      method: 'GET',
      data: {},
      success: function(res) {
        console.log('响应数据:', res);
        if (res.statusCode === 200) {
          that.setData({
            List: res.data.data || []
          });
        } else {
          wx.showToast({
            title: `错误: ${res.statusCode}`,
            icon: 'none'
          });
        }
      },
      fail: function(err) {
        console.error('请求失败:', err);
        wx.showToast({
          title: '网络请求失败',
          icon: 'none'
        });
      },
      complete: function() {
        that.setData({ loading: false });
      }
    });
  },
})